from flask import Blueprint, jsonify, json
from flask_restful import Resource, Api
from common.utils.myredis import myredis
from common.utils.get_data import get_data, _get_data
from second_flask.methods import db1

check_message_bp = Blueprint('check_message_bp', __name__)

api = Api(check_message_bp)


def set_audit(audit_id):
    res = myredis.t_len('userauditlist')
    if res > 0:
        code = myredis.r_pop('userauditlist')
        print('code>>>', code)
        user_id = code[:-15]
        number = (int(user_id.decode()) % 3) + 1
        sql = "update message%d set audit_id=%d where msg_id='%s'" % (int(number), int(audit_id), code.decode())
        db1.update(sql)
        return jsonify({'code': 200})


@check_message_bp.route('/auditmes')
def auditmes():
    sql = "select id from users where role_id=3"
    audit_id = db1.find_all(sql)
    print(audit_id)
    while True:
        for i in audit_id:
            print('id>>>>>>', i['id'])
            set_audit(i['id'])


# @check_message_bp.route('/')
